package com.canto.common.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * Json转换工具类
 */
public class JsonUtil {

    private static Gson gson = null;

    static {
        if (gson == null) {
            gson = new Gson();
        }
    }

    /**
     * Object转String
     *
     * @param object
     * @return
     */
    public static String toObject(Object object) {
        return gson.toJson(object);
    }

    /**
     * 将Object[]转换为String
     *
     * @param object 为Object[]
     * @return
     */
    public static String toArrayObj(Object object) {
        return gson.toJson(object, new TypeToken<Object[]>() {
        }.getType());
    }

}
